import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;

public class get {

    private final static String QUEUE_NAME = "savegroups_failure";
    //private static final String EXCHANGE_NAME = "savegroup_failure";

    public static void main(String[] argv) throws Exception {
    	 String hostname = argv[0]; 
		  String QUEUE_NAME = argv[1]; //=="two"
		      	
    	
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(hostname);
    factory.setVirtualHost("backup");
    factory.setPassword("networker");
    factory.setUsername("backup");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    boolean durable = true;
    channel.queueDeclare(QUEUE_NAME, durable, false, false, null);
    System.out.println(" [*] Waiting for messages in queue " + QUEUE_NAME + "  To exit press CTRL+C");
    
    QueueingConsumer consumer = new QueueingConsumer(channel);
     
    channel.basicConsume(QUEUE_NAME, true, consumer);
    //channel.exchangeDeclare(EXCHANGE_NAME, "direct");
    
    while (true) {
      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
//      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
      String message = new String(delivery.getBody());
      System.out.println(" [x] Received '" + message + "'");
    }
  }
}